﻿package 
{
   import flash.events.Event;
   import flash.events.EventDispatcher;
   
   /*
   * @auther  cjboy1984@gmail.com
   * @date    Oct,8,2010
   * @refer   http://sourcemaking.com/design_patterns/singleton
   */
   public class MyEventMgr extends EventDispatcher
   {
      private static var ins:MyEventMgr;
      
      // as3: A constructor can only be declared public, or it should be a private constructor
      public function MyEventMgr(pvt:PrivateClass)
      {
      }
      
      // ________________________________________________
      //                                             main
      
      // to dispatch event
      public static function send(e:Event):Boolean
      {
         return api.dispatchEvent(e);
      }
      
      // to listen event
      public static function listen(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
      {
         api.addEventListener(type, listener, useCapture, priority, useWeakReference);
      }
      
      // to unlisten event
      public static function unListen(type:String, listener:Function, useCapture:Boolean = false):void
      {
         api.removeEventListener(type, listener, useCapture);
      }
      
      // ________________________________________________
      //                                        singleton
      
      public static function get api():MyEventMgr
      {
         if (!ins)
         {
            ins = new MyEventMgr(new PrivateClass());
         }
         
         return ins;
      }
      
      // ################### protected ##################
      
      // #################### private ###################
      
      // --------------------- LINE ---------------------
      
   }
   
}

class PrivateClass
{
   public function PrivateClass()
   {
   }
}